#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(int a, int b)
{
	return a > b;
}

int main() 
{
    int t;
    cin >> t;
    
    while (t--) 
	{
        int n, k;
        cin >> n >> k;
        
        vector<int> a(n);
        for (int i = 0; i < n; i++) 
		{
            cin >> a[i];
        }

        sort(a.begin(), a.end(), cmp);  

        long long score = 0;
        
        for (int i = 0; i < n; i++) 
		{
        	
            if (i % 2 == 0) 
			{
                score += a[i];
            } else 
			{
                int tmp = min(k, a[i - 1] - a[i]);
                a[i] += tmp;
                k -= tmp;
                score -= a[i];
            }
        }
        
        cout << score << endl;
    }
    
    return 0;
}

